package com.project.business.api;

import com.project.business.service.DeptEntityService;
import com.project.business.entity.DeptEntity;
import com.common.common.Response;
import org.noear.solon.annotation.*;

import java.util.List;

@Mapping("/dept")
@Controller
public class DeptResource {

    @Inject
    private DeptEntityService deptService;

    @Get
    @Mapping
    public List<DeptEntity> getList() {
        return deptService.list();
    }

    @Get
    @Mapping("/{id}")
    public DeptEntity getOne(@Param("id") Integer id) {
        return deptService.getById(id);
    }

    @Post
    @Mapping
    public Response save(DeptEntity entity) {
        deptService.saveOrUpdate(entity);
        return Response.success();
    }

    @Put
    @Mapping("/{id}")
    public Response edit(@Param("id") Integer id, DeptEntity entity) {
        deptService.edit(id, entity);
        return Response.successEdit();
    }
}
